Repository navigation
fix(design-code-proxy): don't forward the backend's Content-Length for re-serialized bodies (#684) - #685
Merged
Conversation
…r re-serialized bodies (#684) writeHead() spread the backend's headers verbatim, including its Content-Length, but the non-stream success path sends a re-serialized body (model rewritten, pretty-printed) that is longer than the backend's compact body — clients read only the backend's byte count and got truncated, unparseable JSON (and corrupt keep-alive framing). writeHead now takes the exact body being sent when it is known and advertises its real length, and drops the stale Content-Length / Transfer-Encoding for the streaming path, whose chunks are also rewritten. Byte-for-byte forwarded bodies keep a correct length (their own byte count). New regression test: a stub backend that sets an explicit Content-Length on its compact JSON success body; the client must receive the full model-rewritten body. Ablation: with only the proxy change reverted, exactly that test fails (JSON.parse at position 191, the backend's length).
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing: 2
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #684
Problem
PR #682's
writeHead()helper inbin/design-code-proxy.mjsspread the backend's response headers verbatim — including itsContent-Length— but the non-stream success path then sends a different body: the parsed JSON re-serialized withmodelrewritten and pretty-printing (JSON.stringify(json, null, 2)). Whenever the backend setsContent-Length(the normal behaviour of a buffered JSON server), the client reads only the backend's byte count and gets truncated, unparseable JSON; on a keep-alive connection the surplus bytes also corrupt the next response's framing.Reproduced on main
c6ec7bd6with a stub backend returning a 191-byte compact JSON body with an explicitContent-Length: 191: the proxy forwardedcontent-length: 191with a 283-byte re-serialized body —JSON.parseof the received body fails at position 191, and a raw HTTP client hitsHPE_INVALID_CONSTANTparsing the leftover bytes as a new response. The existing suite couldn't see it: its stubs never setContent-Length, so Node answered chunked.Solution
writeHead(sentBody)now owns the framing headers:Content-Lengthand lets Node chunk the response.Transfer-Encodingfrom the backend is never forwarded alongside the new framing.Streaming success behaviour is otherwise unchanged, and the byte-for-byte catch branch keeps a correct length (its own byte count).
Tests
ok-length+ regression test backend Content-Length does not truncate the re-serialized success body (design-code-proxy: forwarded Content-Length truncates the re-serialized success body (PR #682) #684): asserts the advertised length (when present) equals the received byte count, the body parses, content and rewrittenmodelare correct, and no fallback call happens.bin/design-code-proxy.mjsreverted, exactly the new test fails, with the issue's exact symptom (JSON.parseerror at position 191); the other 5 design tests still pass.node --test bin/design-code-proxy.test.mjs bin/muse-proxy.test.mjs bin/codex-proxy.test.mjs bin/proxy-port.test.mjs→ 25/25.content-length: 283, full body received, parses,model: design-code-flash.Single-repo:
design-code-proxyhas no copy in developing-today/opencode, developing-today/openchamber, or dezren39/nix (git-grep on each clone'sorigin/main).Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit